package servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class response_1 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 它会同时设置服务器和客户端都使用 UTF-8 字符集，还设置了响应头
        // 此方法一定要在获取流对象之前调用才有效
        resp.setContentType("text/html;charset=utf-8");
        System.out.println("resp  "+resp.getCharacterEncoding());
        System.out.println("req  "+req.getCharacterEncoding());

        resp.getWriter().write("你好");
        resp.sendRedirect("https://www.csdn.net/gather_2b/MtTagg5sNjM0ODktYmxvZwO0O0OO0O0O.jsp");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");
        System.out.println("resp  "+resp.getCharacterEncoding());
        System.out.println("req  "+req.getCharacterEncoding());
        resp.getWriter().write("你好");
    }
}
